<template>
  <Toolbar style="border-bottom: 1px solid #ccc" :editor="editorRef" :defaultConfig="toolbarConfig" />
  <Editor style="height: 500px; overflow-y: hidden;" v-model="content" :defaultConfig="editorConfig"
    @onCreated="handleCreated" />
</template>
<script setup lang="ts">
import '@wangeditor/editor/dist/css/style.css'
import { Editor, Toolbar } from '@wangeditor/editor-for-vue'
import type { IEditorConfig } from '@wangeditor/editor'
const editorRef = shallowRef()
const content = defineModel<string>()
const toolbarConfig = {}
const editorConfig: Partial<IEditorConfig> = {
  MENU_CONF: {}
}
editorConfig.MENU_CONF!['uploadImage'] = {
  base64LimitSize: 5 * 1024 // 5kb
}
onBeforeUnmount(() => {
  const editor = editorRef.value
  if (editor == null) return
  editor.destroy()
})
const handleCreated = (editor: any) => {
  editorRef.value = editor
}
</script>
<style lang="scss">
.btn-close {
  svg {
    display: none;
  }
}
</style>